const ProjectModel = require('../model/projectModel');

const userService = {
    userfindmany: ()=>{
        return ProjectModel.UserModel.find().then(data=>{
            return data
        })
    },

    userfindone: (id)=>{
        return ProjectModel.UserModel.find({id})
        .then(data=>{
            return data
        })
    },

    userfindwho: (username,password)=>{
        return ProjectModel.UserModel.find({username,password})
        .then(data=>{
            if(data.length){
                return data
            }else{
                return false
            }
        })
    },

    useradd: (body)=>{
        let {id,username,name,password,sex,livecity} = body
        return ProjectModel.UserModel.create({id,username,name,password,sex,livecity})
        .then(data=>{
            return true
        })
    },

    userupdata: (body)=>{
        let {username,name,password,sex,livecity} = body
        return ProjectModel.UserModel.updateOne({username},{name,password,sex,livecity})
        .then(data=>{
            return ProjectModel.UserModel.find({username,password})
            .then(item=>{
                return item
            })
        })
    }
}

module.exports = userService